﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Configuration;
using System.Web.Security;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Collections;
using System.IO;
using System.Drawing;
using System.Text;

public partial class projectdan : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["name"] == null)
        {
            Response.Redirect("~/error.aspx?");
        }
        else
        {
            if (!IsPostBack)
            {
                this.bind();
            }
        }
    }

    public SqlConnection GetConnection()
    {
        string myStr = ConfigurationManager.AppSettings["ConnectionString"].ToString();
        SqlConnection myConn = new SqlConnection(myStr);
        return myConn;
    }

    protected void bind()
    {
        SqlConnection myConn = GetConnection();
        myConn.Open();
        string sqlStr = "select ID as 编号,DName as 表单名,DHetong as 合同号,DDes as 表单属性 from Dan where DPID='" + Session["pid"].ToString() + "'and DDes ='购货单'";
        SqlDataAdapter myDa = new SqlDataAdapter(sqlStr, myConn);
        DataSet myDs = new DataSet();
        myDa.Fill(myDs);
        GridView1.DataSource = myDs;
        GridView1.DataKeyNames = new string[] { "编号" };
        GridView1.DataBind();
        myDa.Dispose();
        myDs.Dispose();
        myConn.Close();

        myConn = GetConnection();
        myConn.Open();
        sqlStr = "select ID as 编号,DName as 表单名,DDes as 表单属性 from Dan where DPID='" + Session["pid"].ToString() + "'and DDes ='出货单'";
        myDa = new SqlDataAdapter(sqlStr, myConn);
        myDs = new DataSet();
        myDa.Fill(myDs);
        GridView2.DataSource = myDs;
        GridView2.DataKeyNames = new string[] { "编号" };
        GridView2.DataBind();
        myDa.Dispose();
        myDs.Dispose();

        string sqllabel = "select distinct DHetong from Dan where DPID='" + Session["pid"].ToString() + "'";
        SqlCommand cmd = new SqlCommand(sqllabel, myConn);
        cmd.ExecuteNonQuery();
        SqlDataReader read = cmd.ExecuteReader();
        while (read.Read())
        {
            Label2.Text = Label2.Text + read["DHetong"].ToString()+"  ";
        }
        read.Close();
        myConn.Close();
    }
    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {
        Session["dan"] = GridView1.SelectedValue.ToString();
        SqlConnection myConn = GetConnection();
        myConn.Open();
        // SqlCommand cmd=new SqlCommand();
        string sqlStr = "select * from [Dan] where [id]='" + Session["dan"].ToString() + "' ";
        SqlCommand cmd = new SqlCommand(sqlStr, myConn);
        cmd.ExecuteNonQuery();
        SqlDataReader read = cmd.ExecuteReader();
        read.Read();

        Session.Timeout = 1440;
        Session["DDes"] = read["DDes"].ToString();


        Response.Redirect("~/Dan.aspx?");
    }
    protected void GridView2_SelectedIndexChanged(object sender, EventArgs e)
    {
        Session["dan"] = GridView2.SelectedValue.ToString();
        SqlConnection myConn = GetConnection();
        myConn.Open();
        // SqlCommand cmd=new SqlCommand();
        string sqlStr = "select * from [Dan] where [id]='" + Session["dan"].ToString() + "' ";
        SqlCommand cmd = new SqlCommand(sqlStr, myConn);
        cmd.ExecuteNonQuery();
        SqlDataReader read = cmd.ExecuteReader();
        read.Read();

        Session.Timeout = 1440;
        Session["DDes"] = read["DDes"].ToString();


        Response.Redirect("~/Dan.aspx?");
    }
}